<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/share/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title>题目管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<%@ include file="/WEB-INF/share/easyuilist.jsp"%>
	<style>
      	.ui-underline .ui-select-text{border:1px solid #ccc !important;}
      </style>
    <script type="text/javascript">
    	var loadDataUrl = '${ctx}/subinfo/GetData';
    	var deleteUrl = '${ctx}/subinfo/delete';
    	var detailUrl = '/subinfo/detail';
	    $(function () {
	        InitialPage();
	        GetGrid();
	        
	        $("#drivertype").ComboBox({
	            description: "==请选择==",
	            isuse:true
	        })
	        $("#subtype").ComboBox({
	            description: "==请选择==",
	            isuse:true
	        })
	    });
	    //初始化页面
	    function InitialPage() {
	        //resize重设(表格、树形)宽高
	        $(window).resize(function (e) {
	            window.setTimeout(function () {
	                $('#gridTable').setGridWidth(($('.gridPanel').width()));
	                $("#gridTable").setGridHeight($(window).height() - 136.5);
	            }, 200);
	            e.stopPropagation();
	        });
	    }
	    //加载表格
	    function GetGrid() {
	        var selectedRowIndex = 0;
	        var $gridTable = $('#gridTable');
	        $gridTable.jqGrid({
	            url: loadDataUrl,
	            datatype: "json",
	            height: $(window).height() - 136.5,
	            autowidth: true,
	            postData : {},
	            colModel: [
	                { label: '主键', name: 'id', hidden: true },
	                { label: '题目类型', name: 'drivertype', width: 100, align: 'center' },
	                { label: '科目类型', name: 'subtype', width: 100, align: 'center',
	                	formatter: function (cellvalue, options, rowObject) {
	                		return cellvalue;
	                	}
	                },
	                { label: '名称', name: 'question', width: 470, align: 'left' },
	                { label: '类型', name: 'type', width: 100, align: 'center',
	                	formatter: function (cellvalue, options, rowObject) {
	                		if(cellvalue=='1')return '判断题';
	                		else if(cellvalue=='2')return '单选题';
	                		else if(cellvalue=='3')return '多选题';
	                	}
	                },
	                { label: "排序", name: "xorder", width: 60, align: "center",
	                	formatter: function (cellvalue, options, rowObject) {
	                		return cellvalue;
	                	}
	                },
	                { label: "", name: "", width: 10, align: "left" }
	            ],
	            viewrecords: true,
	            rowNum: 20,
	            rowList: [20,30, 50, 100],
	            pager: "#gridPager",
	            rownumbers: true,
	            shrinkToFit: false,
	            gridview: true,
	            onSelectRow: function () {
	                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
	            },
	            gridComplete: function () {
	            }
	        });
	        //查询事件
	        $("#btn_Search").click(function () {
	            var queryJson = {
	            		drivertype: $("#drivertype").attr('data-value'),
	            		subtype: $("#subtype").attr('data-value'),
	            		question:$('#question').val()
	            }
	            $gridTable.jqGrid('setGridParam', {
	                postData: queryJson, page: 1
	            }).trigger('reloadGrid');
	        });
	    }
	    //新增
	    function btn_add() {
	        dialogOpen({
	            id: "Form",
	            title: '添加题目',
	            url: detailUrl,
	            width: "900px",
	            height: "600px",
	            callBack: function (iframeId) {
	                top.frames[iframeId].AcceptClick();
	            }
	        });
	    };
	    //编辑
	    function btn_edit() {
	        var keyValue = $("#gridTable").jqGridRowValue("id");
	        if (checkedRow(keyValue)) {
	            dialogOpen({
	                id: "Form",
	                title: '修改题目信息',
	                url: detailUrl+'?id=' + keyValue,
		            width: "900px",
		            height: "600px",
	                callBack: function (iframeId) {
	                    top.frames[iframeId].AcceptClick();
	                }
	            });
	        }
	    }
	    //删除
	    function btn_del() {
	        var keyValue = $("#gridTable").jqGridRowValue("id");
	        if (keyValue) {
	            $.RemoveForm({
	                url: deleteUrl,
	                param: { ids: keyValue },
	                success: function (data) {
	                    $("#gridTable").trigger("reloadGrid");
	                }
	            })
	        } else {
	            dialogMsg('请选择需要删除的数据！', 0);
	        }
	    }
	    
	</script>
</head>
<body class="mybody">
	<div class="titlePanel">
	    <div class="title-search">
	        <table>
	            <tr>
	                <td>查询条件</td>
                    <td style="padding-left: 10px;">
                        <div class="ui-filter" style="width: 200px;">
                            <div class="ui-filter-text">
							点击输入关键字查询
                            </div>
                            <div class="ui-filter-list" style="width: 350px;">
                                <table class="form" id="filter-form">
                                    <tr>
                                        <td class="formTitle">名称：</td>
                                        <td class="formValue">
                                            <input id=question type="text" class="form-control" />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="formTitle">题目类型：</td>
                                        <td class="formValue">
                                            <div id="drivertype" style="" type="select" class="ui-select ui-underline">
						                        <ul>
						                            <li data-value="">===请选择===</li>
													<c:forEach items="${CarTypeList}" var="entry">
														<li data-value="${entry.value}">${entry.value}</li>
													</c:forEach>
						                        </ul>
						                    </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="formTitle">科目类型：</td>
                                        <td class="formValue">
                                            <div id="subtype" style="" type="select" class="ui-select ui-underline">
						                        <ul>
						                            <li data-value="">===请选择===</li>
						                            <li data-value="科目一">科目一</li>
						                            <li data-value="科目四">科目四</li>
						                        </ul>
						                    </div>
                                        </td>
                                    </tr>
                                </table>
                                <div class="ui-filter-list-bottom">
                                    <a id="btn_Search" class="btn btn-primary">&nbsp;查&nbsp;&nbsp;询</a>
                                </div>
                            </div>
                        </div>
                    </td>
	            </tr>
	        </table>
	    </div>
	    <div class="toolbar">
	        <div class="btn-group">
	            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
	            <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
	            <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
	            <a id="lr-delete" class="btn btn-default" onclick="btn_del()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
	            
	        </div>
	    </div>
	</div>
	<div class="gridPanel">
	    <table id="gridTable"></table>
	    <div id="gridPager"></div>
	</div>
</body>
</html>
